package com.life.system.action;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.life.system.service.ILoginService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype")
public class LoginAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5698800869111791710L;

	@Resource
	ILoginService loginService;
	
	/**
	 * 
	 * @description 登录
	 * @return
	 * @throws Exception
	 * @created 2012-9-26 下午3:51:11
	 */
	//@JSON
	public String login() throws Exception {
		/*
		UserEntity user = sysFunctionService.validateUser(userVo);

		// 用户不存在
		if (user == null) {
			msg = "-1";
			return SUCCESS;
		}
		
		// 密码错误
		MessageDigest md = MessageDigest.getInstance("MD5");
		byte[] b = md.digest(userVo.getPassWord().getBytes());
		BASE64Encoder encoder = new BASE64Encoder();
		String pwd = encoder.encode(b);
		if (!pwd.equals(user.getPassWord())) {
			msg = "0";
			return SUCCESS;
		}
		
//		if(!sysFunctionService.checkUser(userVo)){
//			msg = "2";
//			return SUCCESS;
//		}
		
		// 正确登陆，绑定session
		ActionContext context = ActionContext.getContext();
		Map<String, Object> sessions = context.getSession();
		sessions.put("user", user);
		*/
		return SUCCESS;
	}
	
	/**
	 * 生成树
	 * @return
	 */
	public String initTree() throws Exception {
		/*
		ActionContext context = ActionContext.getContext();
		Map<String, Object> sessions = context.getSession();
		UserEntity user = (UserEntity) sessions.get("user");
		UserTreeVo userTree = new UserTreeVo();
		userTree.setId(id);
		userTree.setEmpCode(user.getEmpCode());
		tree = sysFunctionService.queryTree(userTree);
		*/
		return SUCCESS;
	}

	/**
	 * 
	 * @description 登出
	 * @param uservo
	 * @throws Exception
	 * @created 2012-9-26 下午4:01:27
	 */
	public String logout() throws Exception {
		ActionContext context = ActionContext.getContext();
		Map<String, Object> sessions = context.getSession();
		sessions.remove("user");
		return SUCCESS;
	}
}
